package com.xyd.servlet;

import com.xyd.entity.Comment;
import com.xyd.entity.PageBean;
import com.xyd.service.CommentService;
import com.xyd.service.impl.CommentServiceImpl;
import com.xyd.util.JsonUtil;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 类描述：
 *
 * @author 张吉哲
 * @date 2021/1/11 13:35
 */
@WebServlet("/commentShowServlet")
public class CommentShowServlet extends HttpServlet {

  @Override
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    CommentService commentService = new CommentServiceImpl();
    String currentPage_str = request.getParameter("currentPage");
    int currentPage = 1;
    if (currentPage_str != null && currentPage_str.length() > 0) {
      currentPage = Integer.parseInt(currentPage_str);
    }
    PageBean<Comment> pb = commentService.findComment(currentPage);
    JsonUtil.toJson(response, pb);

  }

  @Override
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    doPost(request, response);
  }
}
